/**
 * FileName: SpikeController
 *
 * @author: 阿张
 * Date:     2021/2/25 14:28
 */
package com.qx.controller;

import com.qx.pojo.ScAddress;
import com.qx.service.ScAddressService;
import com.qx.service.SpikeService;
import lombok.SneakyThrows;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import result.Result;
import result.ResultFactory;

import javax.annotation.Resource;

@RestController
@RequestMapping("app/spike")
public class SpikeController {

    @Resource
    private SpikeService spikeService;

    @Resource
    private ScAddressService scAddressService;

    @Resource
    private RedisTemplate<String, Integer> redisTemplate;

    @SneakyThrows
    @RequestMapping(value = "/SpikeGoods/{deploy_id}&{commodity_id}",method = RequestMethod.POST)
    public Result spikeShop(@PathVariable("deploy_id") Integer deploy_id, @PathVariable("commodity_id")Integer commodity_id){
        if (spikeService.addSpikeCommodity(deploy_id, commodity_id)){
            return ResultFactory.buildSuccessResult("秒杀成功");
        }
        return ResultFactory.buildFailResult("秒杀失败");
    }

    @RequestMapping(value = "/orderFrom/{commodity_id}",method = RequestMethod.POST)
    public void orderFrom(@PathVariable("commodity_id")Integer commodityId, @RequestBody ScAddress address){
        redisTemplate.opsForHash().put(""+1,commodityId,address);
    }
}
